#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
int n = 30, m = 40;
int mp[32][42];
int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };

//int fastPower(int base, int power, int mod)
//{
//	int ret = 1;
//	base %= mod;
//	while (power > 0)
//	{
//		if (power & 1)
//		{
//			ret = (ret * base) % mod;
//		}
//		base = (base * base) % mod;
//		power >>= 1;
//	}
//	return ret;
//}

//int clac(int m)
//{
//	int num = 0;
//	for (int i = 1; i <= m; i++)
//	{
//		if (m % i == 0)
//			num++;
//	}
//	return num;
//}

/*bool clac(int m)
{
	int a = 0, b = 0;
	int mb = m;
	while (m)
	{
		a += m % 2;
		m /= 2;
	}
	while (mb)
	{
		b += mb % 8;
		mb /= 8;
	}
	return a == b;
}*/

void dfs(int x, int y)
{
	if (mp[x][y] == 2)
		return;
	mp[x][y] = 2;
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (nx > 0 && nx < 31 && ny>0 && ny < 41 && mp[nx][ny] == 0)
		{
			dfs(nx, ny);
		}
	}
}

int main()
{
	//cout << fastPower(2, 2023, 1000);
	/*int n = 0, maxn = 0;
	for (int i = 0; i < 36; i++)
	{
		cin >> n;
		maxn = clac(maxn) > clac(n) ? maxn : n;
	}
	cout << maxn;*/
	/*int n = 0, i = 1;
	while (n < 23)
	{
		if (clac(i))
			n++;
		i++;
	}
	cout << --i;*/
	for (int row = 1; row <= 30; row++)
		for (int col = 1; col <= 40; col++)
			cin >> mp[row][col];
	dfs(1, 1);
	int ret = 0;
	for (int row = 1; row <= 30; row++)
	{
		for (int col = 1; col <= 40; col++)
		{
			if (mp[row][col] == 2)
			{
				ret++;
			}
		}
	}
	cout << ret;
}